package com.aramco.fion.vo
{
	import com.aramco.fion.model.FlexConstants;
	import com.aramco.fion.util.AdminUtil;
	
	import flash.utils.describeType;
	import flash.utils.getQualifiedClassName;
	
	import mx.collections.ArrayCollection;
	
	//import org.purepdf.errors.CastTypeError;
	//import org.purepdf.pdf.fonts.StreamFont;

	public class ComponentVO
	{
		public function ComponentVO()
		{
			createdOn = new dateVO("");
			changedOn = new dateVO("");
		}
		
		[Bindable]
		public var id:String  = "";
		public var title:String = "";
		public var description:String = "";
		public var config:XMLList ;
		private var _options:String = "";
		public var type:String = "";
		public var queryName:String  = "";
		public var url:String = "";
		public var selections:ArrayCollection ;
		public var dashboardId:String = "";
		public var createdBy:String = "";
		public var createdOn:dateVO ;
		public var changedBy:String = "";
		public var changedOn:dateVO;
		public var notActive:Boolean  = false;
		public var mobile:Boolean = false;
		public var schedule:Boolean =  false;
		public var zorder:String = "";
		public var note:String = "";
		public var drillTo:String = "";
		public var drillVars:String = "";
		
		
		
		public function get options():String
		{
			if(config != null)
				return config.toString();
			else
				return "";
		}

		public function set options(value:String):void
		{
			config = value as XMLList;
		}

		public function toXML():XML
			
		{	
			var rowXML:XML = new XML('<row/>');
			var dataXML:XML;

				dataXML = new XML('<data/>');
				
				//  Component identification number
				rowXML.@recordID = id;
				
				// Component identification number
				dataXML.@name =  AdminUtil.compTableFields[0];
				dataXML.@value = id;
				rowXML.appendChild(dataXML);
				
				
				// Dashboard ID
				dataXML = new XML('<data/>');
				dataXML.@name =  AdminUtil.compTableFields[1];
				dataXML.@value = dashboardId.toString();
				rowXML.appendChild(dataXML);
				
				// Title
				dataXML = new XML('<data/>');
				dataXML.@name =  AdminUtil.compTableFields[2];
				dataXML.@value = title.toString();
				rowXML.appendChild(dataXML);
				
				// Description
				dataXML = new XML('<data/>');
				dataXML.@name =  AdminUtil.compTableFields[3];
				dataXML.@value =  description.toString();
				rowXML.appendChild(dataXML);
				
				// Component Type
				dataXML = new XML('<data/>');
				dataXML.@name =  AdminUtil.compTableFields[4];
				dataXML.@value = type.toString();
				rowXML.appendChild(dataXML);
				
				// Query 
				
				dataXML = new XML('<data/>');
				dataXML.@name =  AdminUtil.compTableFields[5];
				dataXML.@value = queryName.toString();
				rowXML.appendChild(dataXML);
				
				// Created by
				dataXML = new XML('<data/>');
				dataXML.@name =  AdminUtil.compTableFields[6];
				dataXML.@value = createdBy.toString();
				rowXML.appendChild(dataXML);
				
				// Created on
				dataXML = new XML('<data/>');
				dataXML.@name =  AdminUtil.compTableFields[7];
				dataXML.@value = createdOn.value.toString();
				rowXML.appendChild(dataXML);
				
				// Last Changed by User
				dataXML = new XML('<data/>');
				dataXML.@name =  AdminUtil.compTableFields[8];
				dataXML.@value = changedBy.toString();
				rowXML.appendChild(dataXML);
				
				// Changed On 
				dataXML = new XML('<data/>');
				dataXML.@name =  AdminUtil.compTableFields[9];
				dataXML.@value = changedOn.value;
				rowXML.appendChild(dataXML);
				
				// Inactive flag 
				dataXML = new XML('<data/>');
				dataXML.@name =  AdminUtil.compTableFields[10];
				dataXML.@value = notActive? 'X' : '';
				rowXML.appendChild(dataXML);
				
				// Note
				dataXML = new XML('<data/>');
				dataXML.@name =  AdminUtil.compTableFields[11];
				dataXML.@value = note.toString();
				rowXML.appendChild(dataXML);
				
				// Drill To
				dataXML = new XML('<data/>');
				dataXML.@name =  AdminUtil.compTableFields[12];
				dataXML.@value = drillTo.toString();
				rowXML.appendChild(dataXML);
				
				// Drill Vars
				dataXML = new XML('<data/>');
				dataXML.@name =  AdminUtil.compTableFields[13];
				dataXML.@value = drillVars.toString();
				rowXML.appendChild(dataXML);
				
				// Options
				dataXML = new XML('<data/>');
				dataXML.@name =  AdminUtil.compTableFields[14];
				dataXML.@value = options;
				rowXML.appendChild(dataXML);
				
				// Mobile enabled component
				dataXML = new XML('<data/>');
				dataXML.@name =  AdminUtil.compTableFields[15];
				dataXML.@value = mobile? 'X' : '';
				rowXML.appendChild(dataXML);
				
				// Schedulable component
				dataXML = new XML('<data/>');
				dataXML.@name =  AdminUtil.compTableFields[16];
				dataXML.@value = schedule ? 'X' : '';
				rowXML.appendChild(dataXML);
				
				// Component URL
				dataXML = new XML('<data/>');
				dataXML.@name =  AdminUtil.compTableFields[17];
				dataXML.@value = url.toString();
				rowXML.appendChild(dataXML);
				
			return rowXML; 

		}
	}
}